import bpy

from ..utils.log import log
from .property import TestProperty
from .export_render_file import TestExportFile
from .asset_import import TestAssetImport
from .operator import TestOperator

class_list = (
    TestProperty,
    TestAssetImport,
    TestExportFile,
    TestOperator,
)

DEBUG = False


def run_test():
    log.debug("unittest Render Master")
    from .utils import test_class_list
    test_class_list(class_list)


def run_unittest():
    global DEBUG
    for area in bpy.context.screen.areas:
        if DEBUG and area.type == "VIEW_3D":
            log.debug("test unittest")
            import unittest
            unittest.main(exit=False, module=__package__)
            DEBUG = False
    return 1


def reg_test():
    log.debug("reg_test run_unittest render_master")
    bpy.app.timers.register(run_unittest, first_interval=1)


def register():
    reg_test()


def unregister():
    if bpy.app.timers.is_registered(run_unittest):
        bpy.app.timers.unregister(run_unittest)
